package com.Atao.service.impl;

import com.Atao.mapper.CategoryMapper;
import com.Atao.pojo.Category;
import com.Atao.service.CategoryService;
import com.Atao.utils.ThreadLocalUtil;
import com.Atao.utils.getIdUtil;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(Category category) {
        //补充属性值
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        Integer userId = getIdUtil.getId();
        category.setCreateUser(userId);
        categoryMapper.add(category);
    }

    @Override
    public List<Category> list() {
        Integer userId= getIdUtil.getId();
        return categoryMapper.list(userId);
    }

    @Override
    public Category findById(Integer id) {
        Category c=categoryMapper.findById(id);
        return c;
    }

    @Override
    public void update(Category category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }

    @Override
    public void delete2(String categoryName) {
        Integer id=getIdUtil.getId();
        System.out.println("id:"+id);
        categoryMapper.delete2(id,categoryName);
    }

    @Override
    public Integer getIdByName(String categoryName) {
        return categoryMapper.getIdByName(categoryName);
    }
}
